var ajax = require('../../utils/ajax.js');
var util = require('../../utils/util.js');
var Base = require('../base.js');
var app = getApp();
var curPage;
var curScope;
var _timerId;
var _timerList = {};

function init({
  page,
  scope,
}) {
  curPage = page;
  curScope = scope || 'groupBuy';

  _initData();
}

function _initData() {
  ajax.G('/openapi/CActivity/groupBuyActList', {}, function(data) {
    var actList = data.result.actList;

    _setData({
      actList,
    });
  });
}

function _setData(data) {
  var obj = _getData();

  Object.assign(obj, data);

  curPage.setData({
    [`${curScope}`]: obj
  });
}

function _getData(key) {
  var data = curPage.data[`${curScope}`] || {};

  if (!key) {
    return data;
  } else {
    return data[key];
  }
}

module.exports = {
  init
};